package jianli;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/LogoutServlet")
public class LogoutServlet extends HttpServlet{
    private static final long serialVersionUID = 1L;
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();//实现请求转发即服务器端跳转，跳转HTML页面如果中文乱码,尝试去掉此行代码
        HttpSession session=request.getSession();
        session.invalidate(); //session失效
       // response.setHeader("refresh","2;URL=login.html");//客户端跳转，定时刷新
       // response.sendRedirect("login.html");//客户端跳转，即刻跳转
//        request.getRequestDispatcher("/login.jsp").forward(request, response);//服务器端跳转
        out.println("<HTML>");
        out.println("  <HEAD><TITLE>注销！</TITLE></HEAD>");
        response.setHeader("refresh","2;URL=login.jsp");//定时跳转
        out.println("<h3>您已成功退出本系统，两秒后跳转到首页！</h3><br>");
        out.println("<h3>如果没有跳转，请按<a href='index.jsp'>这里</a></h3>");
        out.println("</BODY>");
        out.println("</HTML>");
    }
}